<?php
class wd_page_widget extends WP_Widget
{  
    public function wd_page_widget()
    {  
      $widgetOptions = array( 'description' => 'Pozwala na wyświetlenie kontenera z treścią wybranej strony');
      parent::WP_Widget(false, __('WD Page'), $widgetOptions);  
    }  
    
    public function form($instance)
    {       
        $formWrapper = '<p><label for="%1$s">%2$s</label><input class="widefat" id="%1$s" name="%3$s" type="text" value="%4$s" /></p>';
        
        $title = sprintf($formWrapper, $this->get_field_id('title'), __('Title:'), $this->get_field_name('title'), esc_attr($instance['title']));        
               
        $slug = sprintf($formWrapper, $this->get_field_id('slug'), __('Slug:'), $this->get_field_name('slug'), esc_attr($instance['slug']));
              
        print $title.$slug;
    }
    
    public function update($new_instance, $old_instance)
    {  
        return $new_instance;  
    }
    
    public function widget($args, $instance)
    {  
        $args['title'] = $instance['title'];  
        
        $args['slug'] = $instance['slug'];  
                
        self::display($args['slug'],  $args['title']);
    }  
    
    
    public static function display($slug, $title = null)
    {       
      $postId = get_ID_by_slug($slug);

      $page_data = get_page($postId); 
      
      print '<div class="widget widget_wd_page">';
      
      if(!is_null($title))
      {
        printf('<h3 class="widget-title">%s</h3>', $title);
      }     
      
      printf('<div class="widget-content textwidget">%s</div>',  apply_filters('the_content', $page_data->post_content));  
      
      if($title != null)
      {
        print '</div>';
      }
    }     
}  

register_widget('wd_page_widget');  
?>